package com.zjsru.oneDay;

/**
 * 甲板上的战舰
 * 输出战舰队列的数量
 * 输入：board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]
 * 输出：2
 * <p>
 * 输入：board = [["."]]
 * 输出：0
 */
public class countBattleships {
    public int countBattleships(char[][] board) {
        int row = board.length;
        int col = board[0].length;
        int ans = 0;
        for (int i = 0; i < row; ++i) {
            for (int j = 0; j < col; ++j) {
                if (board[i][j] == 'X') {
                    board[i][j] = '.';
                    for (int k = j + 1; k < col && board[i][k] == 'X'; k++) {
                        board[i][k] = '.';
                    }
                    for (int k = i + 1; k < row && board[k][j] == 'X'; k++) {
                        board[k][j] = '.';
                    }
                    ans++;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        countBattleships countBattleships = new countBattleships();
        char[][] ch = new char[][]{{'X', '.', '.', 'X'}, {'.', '.', '.', 'X'}, {'.', '.', '.', 'X'}};
        int result = countBattleships.countBattleships(ch);
        System.out.println(result);
    }
}
